<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app1"></div>
    <div id="app2"></div>
    <div id="app3"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入prop-type 用于限制props属性标签 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    
    <script type="text/babel">
        // 假数据
        const obj = {name:"张三",age:18,sex:"男"}
        // 创建组件
        function Person(props) {
            const {name,age,sex} = props
            return (
                <div>
                    <h1>{name}</h1>
                    <h2>{age}</h2>
                    <h2>{sex}</h2>
                </div>
            )
        }
        // 对标签属性进行限制
        Person.propTypes = {
            name:PropTypes.string.isRequired,//限制name必传且为String类型
            age:PropTypes.number,//限制age为number类型
            sex:PropTypes.string,//限制sex为String类型
            speak:PropTypes.func//限制speak为函数类型
        }
        Person.defaultProps = {
            age:18,//指定age默认值
            sex:'保密'//指定sex默认值
        }

        ReactDOM.render(<Person {...obj}/>,document.querySelector('#app2'))
    </script>
</body>
</html>